using System;
using System.Globalization;
using Avalonia.Data.Converters;
using DesktopApp.Models; // For RuleType
using DesktopApp.ViewModels; // For potential access to helper methods if needed directly

namespace DesktopApp.Converters
{
    public class RuleTypeToDisplayNameConverter : IValueConverter
    {
        public static readonly RuleTypeToDisplayNameConverter Instance = new();

        public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
        {
            if (value is RuleType ruleType)
            {
                // Reuse the logic from RulesViewModel.GetRuleTypeDisplayName (copied here for simplicity)
                return GetRuleTypeDisplayName(ruleType);
            }
            return "未知分组"; // Default or error value
        }

        public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
        {
            throw new NotSupportedException();
        }

        // Copied helper method (consider moving to a shared utility class)
        private string GetRuleTypeDisplayName(RuleType type)
        {
             return type switch
             {
                 RuleType.FilterIncludes => "包含规则 (FilterIncludes)",
                 RuleType.FilterExcludes => "排除规则 (FilterExcludes)",
                 RuleType.KeywordReplace => "关键词替换 (KeywordReplace)",
                 RuleType.RegexReplace => "正则替换 (RegexReplace)",
                 RuleType.RemoveTimestamps => "移除时间戳 (RemoveTimestamps)",
                 RuleType.RemoveFilePaths => "移除文件路径 (RemoveFilePaths)",
                 _ => $"{type} (未知类型)" // Default case, ensuring English name is also included
             };
        }
    }
} 